package cn.xz.dao;

import java.sql.*;

/**
 * 饿汉单例
 * 空间换时间 线程安全
 */

public class BaseDaoSingleton {
    private static Connection con = null;
    private BaseDaoSingleton(){}
    static{
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sy", "root", "123456");
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }
    public static Connection getCon(){
        return  con;
    }
    public static void closeAll(ResultSet rs, Statement sta,Connection con){

            try {
                if(rs!=null) {
                rs.close();
            }
                if(sta!=null){
                    sta.close();
                }
                if(con!=null){
                    con.close();
                }
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }


    }
}
